<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建项目</title>
    <link href="../css/creat-pro.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<!--header-->
<header id="header" class="header">
    <div class="header-info left"><i></i><a href="mems-pro-creat.html">创建项目</a></div>
    <div class="right-user right">
         <div class="clear t" >             <div id="headusername" class="role"></div>             <div class="icon"></div>         </div>
        <div class="head-down">
            <ul><li><a href="edit-pwd.html">修改密码</a></li><li><a onclick="loginOut()">退出系统</a></li></ul></div><div>
    </div>
    </div>
</header>
<!--menu-->
<aside id="aside" class="aside">
    <div class="logo">运营平台</div>
    <ul class="menu" id="asidemenu">
    </ul>
</aside>


<!--content-->
<div class="content">
    <div class="creat-pro">
        <div class="pro-head"><i></i>创建项目</div>
        <div class="steps">
            <div class="line">
                <i class="done"></i>
                <i></i>
            </div>
            <div class="circle">
                <p class="done">1</p><p class="done">2</p><p>3</p>
            </div>
            <div class="s-d">
                <p class="done">选择医院</p><p class="done">完善信息</p><p>完成</p>
            </div>
        </div>

        <table class="pro-table">
            <thead>
                <tr>
                    <th width="100">基本信息</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><span class="red-start">*</span>医院全称</td>
                    <td><input type="" name="" id="name"></td>
                    <!---->
                </tr>
                <tr>
                    <td>简称</td>
                    <td><input type="" name="" id="shortName"></td>
                </tr>
                <tr>
                    <td>别称</td>
                    <td><input type="" name="" id="alias"><span style="color: #009926;padding: 0 0 0 5px">多个别称，用英文","隔开</span></td>
                </tr>
                <tr>
                    <td><span class="red-start">*</span>Segmentation</td>
                    <td><select id="segmentation"></select></td>
                </tr>
                <tr>
                    <td><span class="red-start">*</span>级别</td>
                    <td><select id="level"></select></td>
                </tr>

                <tr>
                    <td><span class="red-start">*</span>有无高铁</td>
                    <td><label><input type="radio" value="1" name="hsrEnable">&nbsp;有</label>&emsp;<label><input type="radio" name="hsrEnable" checked="checked" value="0">&nbsp;无</label></td>
                </tr>
                <tr>
                    <td width="150"><span class="red-start">*</span>是否为百强医院</td>
                    <td><label><input type="radio" value="1" name="isTopHundred">&nbsp;是</label>&emsp;<label><input type="radio" name="isTopHundred" checked="checked" value="0">&nbsp;否</label></td>
                </tr>
                <!--<tr>-->
                    <!--<td>邮编</td>-->
                    <!--<td><input type="" name="" class="short" id="postcode"></td>-->
                <!--</tr>-->
                <tr>
                    <td>床位</td>
                    <td>
                        <div class="clearfix number">
                        <a href="javascript:;" class="left sub" onclick="subNum()">-</a>
                        <input onblur="this.value=(this.value+'').replace(/\D/g,'');" class="left" value="1" id="bed">
                        <a class="left add" onclick="addNum()">+</a>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>年诊疗人次</td>
                    <td><input type="" name="" class="short" id="people"></td>
                </tr>
                
            </tbody>
            <thead>
                <tr>
                    <th width="100">地址信息</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><span class="red-start">*</span>所属区域</td>
                    <td><select id="district" onchange="$(this).removeClass('error-i')"><option>请选择</option></select>&emsp;<select onchange="$(this).removeClass('error-i')" id="province"><option>请选择</option></select>&emsp;<select onchange="$(this).removeClass('error-i')" id="city"><option>请选择</option></select></td>
                </tr>
                <tr>
                    <td><span class="red-start">*</span>地址</td>
                    <td><input type="" name="" class="short" id="address"></td>
                </tr>
                <!--<tr>-->
                    <!--<td colspan="2">-->
                        <!--<iframe style="width: 700px;height: 500px" id="test" src='https://m.amap.com/picker/?total=1&center=103.990891,30.700209&key=608d75903d29ad471362f8c58c550daf'></iframe>-->
                    <!--</td>-->
                <!--</tr>-->
                <tr>
                    <td>设备科位置</td>
                    <td><input type="" name="" class="short" id="location"></td>
                </tr>
                <!--<tr>-->
                    <!--<td>维度</td>-->
                    <!--<td><input type="" name="" class="short" id="latitude"></td>-->
                <!--</tr>-->
                <!--<tr>-->
                    <!--<td>经度</td>-->
                    <!--<td><input type="" name="" class="short" id="longitude"></td>-->
                <!--</tr>-->
            </tbody>
            <tbody>
                <tr>
                    <td></td>
                    <td><a class="pro-btn" href="mems-pro-creat-1.html">上一步</a>&emsp;<a class="pro-btn pro-sure pro-sure-can" onclick="creatItem()">提交</a></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<script src='../js/jquery.min.js'  type="text/javascript"></script>
<script src="../js/jquery.cookie.js"></script>
<script src="../js/common.js"></script>
<script type="text/javascript">

    _API.dynamicDistrick('district','province','city');
    var position = $$.getUrlParaObj('p');
    if(position){
        var hdata =  JSON.parse(localStorage.getItem("hospitalData"));
        $('#name').val(hdata.name);
        $('#bed').val(hdata.bedNum);
        $('#address').val(hdata.address);

        _API.getDistrict('district',hdata.area,true)
            .getPrivence('province',hdata.province,true,hdata.area)
            .getCity('city',hdata.city,true,hdata.area,hdata.province)
            .getPSegmentationList('segmentation',hdata.segmentation,false)
            .getPLevelList('level',hdata.grade,false)


    }else{

        _API.getPSegmentationList('segmentation')
            .getPLevelList('level')

    }
    //权限控制
    var roleid = $.cookie('userrole');
    if(roleid == 1 || roleid == 2 ){
        $('#name').prop({'disabled':'disabled'});
        $('#segmentation').prop({'disabled':true})
    }

    function reInputName(that) {
        $(that).removeClass('error-i');
        $(that).sibling('span').css({'display':'none'});
    }

    function addNum() {
        var input = $('#bed');
        var val = parseInt(input.val());
        var newVal = val + 1;
        input.val(newVal );
    }
    function subNum() {
        var input = $('#bed');
        var val = parseInt(input.val());
        var newVal = val - 1;
        if(newVal <= 1){
            newVal = 1;
        }
        input.val( newVal );
    }


    var arr = ['name','address'];
    for(var k = 0; k < 2; k ++){
        $('#'+arr[k]).focus(function(){
            $(this).removeClass('error-i');
        })
    }
    var isClick = false;
    function creatItem() {

        var flag = true;
        for(var k = 0; k < 2; k ++){
            var v = $('#'+arr[k]).val();
            if(v == ""){
               $('#'+arr[k]).addClass('error-i');
                flag = false;
               break;
            }
        }
        var district = $('#district').find('option:selected').text();
        var province = $('#province').find('option:selected').text();
        var city = $('#city').find('option:selected').text();
        if(district == '请选择'){
            $('#district').addClass('error-i');
            return false;
        }
        if(province == '请选择'){
            $('#province').addClass('error-i');
            return false
        }
        if(city == '请选择'){
            $('#city').addClass('error-i');
            return false;
        }

        if(!flag) return;
        var url  = _ip+'/project/insert';
        var data = {
            "name": $('#name').val(),
            "shortName":$('#shortName').val() || null,
            "alias":$('#alias').val() || null,
            "segmentation": $('#segmentation').val(),
            "level": $('#level').val(),
            "hsrEnable":parseInt($('input[name=hsrEnable]:checked').val()),
            "isTopHundred":parseInt($('input[name=isTopHundred]:checked').val()),
            "bed":parseInt($('#bed').val()),
            "people":parseInt($('#people').val()),
            "province": $('#province').val() || '',
            "city": $('#city').val() || '',
            "area": $('#district').val() || '',
            "address":$('#address').val() || '',
            "location":$('#location').val() || null,
            "creater": $.cookie('userid')
        }
        if(position){
            data['hosId'] = hdata.id;
        }
        if(isClick) return;
        $('.pro-sure-can').addClass('sending');
        isClick = true;
        $.ajax({
            url:url,
            type : "POST",
            xhrFields: {
               withCredentials: true
            },
            crossDomain: true,
            dataType: 'json',
            contentType:'application/json',
            data:JSON.stringify(data),
            success:function(data){
                if(data.message === 'LOGIN') {
                    location.href = 'user-login.html';
                    return false;
                }
                if(data.success){
                    var id = data.data;
                   location.href = 'mems-pro-creat-3.html?id='+id+'&name='+$('#name').val();
                }else{
                    $(that).removeClass('sending');
                    isClick = false;
                    if(data.message == '项目名重复，请重新输入'){
                        $('#name').addClass('error-i')
                    }
                    alert(data.message);
                }
            }
        })
   }
</script>
</body>
</html>